<template>
	<div class="content">
		<div class="main">
			<!-- 第一个tabs 基本信息 药典 -->
			<el-dialog title="修改药典目录" :visible.sync="EditDialogFormVisible" width="68%" :before-close="handleEditClose">
			<!-- Main -->
			<el-tabs type="border-card">
			  <el-tab-pane label="基本信息[F2]">
				<!-- 表单 -->
				<el-form ref="form" :model="editForm" size="mini">
					<el-row :gutter="20">
						<el-col :span="v.spanRows" type="flex" v-for="(v,i) in formType" :key="i">
						  <!-- input -->
						  <el-form-item v-if="v.type == 'input'" :label="v.label">
							<el-input v-if="v.zdy" v-autoCode="$data.editForm[v.modelValue]" v-model="$data.editForm[v.modelValue]" :disabled="v.disabled"></el-input>
							<el-input v-else v-model="$data.editForm[v.modelValue]" placeholder="请输入内容" @blur="inputChance(v,i)"></el-input>
						  </el-form-item>
						  <!-- cascader -->
						  <el-form-item v-if="v.type == 'cascader'" :label="v.label">
							<el-cascader :disabled="cascaderdisabled" :props="props" v-model="editForm.nativePlace" placeholder="请选择地区" @change="handleSelectCost">
							</el-cascader>
						  </el-form-item>
						  <!-- select -->
						  <el-form-item v-if="v.type == 'select'" :label="v.label">
							<el-select v-model="$data.editForm[v.modelValue]" :disabled="v.disabled ? disabledKss : v.disabled" filterable
							placeholder="请选择" @focus="handlefoucs(v,i)" @change="handleChange(v,i)">
								<!-- 自定义下拉图标 -->
								<template v-if="v.prefixIcon" #prefix><i class="el-icon-ggml"></i></template>
								<el-option v-for="item in $data[v.op]" :key="item.label" :label="item.label" :value="item.id"> 
								<span style="float: center; color: #8492a6; font-size: 12px">{{ item.label }}</span></el-option>
							</el-select>
						  </el-form-item>
						  <!-- textarea -->
						  <el-form-item v-if="v.type == 'textarea'" :label="v.label">
							<el-input type="textarea" :rows="4" placeholder="请输入内容" v-model="$data.editForm[v.modelValue]"></el-input>
						  </el-form-item>
						</el-col>
					</el-row>
				</el-form>
			  </el-tab-pane>
			  <el-tab-pane label="药典说明[F3]">药典说明</el-tab-pane>
			  <el-tab-pane label="使用注意[F4]">使用注意</el-tab-pane>
			  
			</el-tabs>
			<div slot="footer" class="dialog-footer">
				<el-button size="mini" type="primary" @click="editNewDiction">修改</el-button>
				<el-button size="mini" @click="editDialogFormVisible = false">取消</el-button>
			</div>
			</el-dialog>
		</div>
		<div class="feet">
			
		</div>
	</div>
</template>

<script>
	// selfs / props
	
	// selfs / js
	import editForm from './addForm.js' //Form表单
	import editDialogType from './editDialogType.js' //Form表单
	// axios
	import {   
		ProductNameCode,getDrugType,selectDrugDosageForm,addDrugs,updateDrugCatalogue,
		selectCateGory,selectOneCateGory,selectTwoCateGory,selectThreeCateGory,
		selectDocVtByType,getRecordCategory,
	} 
	from "@/api/MedicenCata.js";
	export default {
		inject: ['reload'], // 无痕刷新
		components: {
			
		},
		data() {
			return {
				// str
				idcode:'', //参数储存 IdCode
				idcodeIII:'', //参数储存 IdCode
				// number
				idx:0,
				// blean
				disabledKss:true,
				EditDialogFormVisible:false, // model
				// arr
				formType:[],
				YNoptions:[{id:1,label:'是',value:'是'},{id:2,label:'否',value:'否'}],
				statusOption:[{id:1,label:'可用',value:'可用'},{id:2,label:'锁定',value:'锁定'}],
				isAntibioticOption:[{id:1,label:'一级抗生素',value:'一级抗生素'},{id:2,label:'二级抗生素',value:'二级抗生素'},{id:3,label:'三级抗生素',value:'三级抗生素'}],
				drugTypeOption:[], //药品类型
				drugDosageOption:[], //ypjx
				drugCategoryOption:[], // yllb I
				drugCategoryChildOption:[], //yllb II
				threeLevelDrugCategoryOption:[], //ypjx
				poisonousTypeOption:[], //dm
				medicalRecordFeeOption:[], //病案费别
				// obj
				editForm:{}, //form表单 * 
				// external
				pickerOptions: {
					shortcuts: [{ text: '今天', onClick(picker) { picker.$emit('pick', new Date()) }}, 
					{ 
						text: '昨天', onClick(picker) { const date = new Date(); date.setTime(date.getTime() - 3600 * 1000 * 24); picker.$emit('pick', date)}
					}, 
					{	text: '一周前',	onClick(picker) { const date = new Date(); date.setTime(date.getTime() - 3600 * 1000 * 24 * 7); picker.$emit('pick', date)}
					}]
				},
				// props
				
				//zdy
				
			}
		},
		// life
		mounted() {
			this.editForm = editForm.map(v => {return v })[0]; // Form
			this.formType = editDialogType.map(v=>{ return v}) // Form
			console.log(this.editForm,'uygahoifua');
		},
		methods: {
			/* 数据源 */
			loadData(){
				
			},
			testOption(){
				
			},
			// 子组件方法被调用，接收到的参数
			openeditdialog(row){
				this.editForm = row;
				this.EditDialogFormVisible = true // 调用子组件打开新增Model
				this.drugCategory != '' ? this.disabledKss = false : this.disabledKss = true
			},
			// 确定修改
			async editNewDiction(){		
				// 自定义赋值
				// this.addForm.code = JSON.parse(sessionStorage.getItem('deptCode'))
				console.log('修改提交',this.editForm);
				// let result = await updateDrugCatalogue(this.editForm)
				// if (result.code === 200){
				// 	this.$message({ type: "success", message: result.message });
				// 	// 更新数据驱动
				// 	this.reload();
				// 	this.EditDialogFormVisible = false
				// }else{
				// 	//验证失败
				// 	this.$message({ type: "error", message: result.message });
				// }
				// console.log(this.editForm);
			},
			/* props */
			// select聚焦
			async handlefoucs(v,i){
				this.idx = i;
				// i event  suffixIcon 为接口
				switch (i) {
					case 1: //药品类型 
						let res = await selectCateGory();
						if(res.code===200){ this.drugTypeOption=res.data }
					break;
					case 2: //有效状态
						this.statusOption=this.statusOption
					break;
					case 5: //药品剂型
						let res1 = await selectDrugDosageForm();
						if(res1.code===200){ this.drugDosageOption = res1.data.map(v => {return { label: v.dosageName , ...v }})}
					break;
					case 8: //药理类别
						let res2 = await selectOneCateGory({drugCategoryName:this.addForm.drugCategoryName});
						if(res2.code===200){ this.drugCategoryOption=res2.data }
					break;
					case 9: //药理子类别
						let resII = await selectTwoCateGory({idcode:this.idcode,drugCategoryChildName:this.addForm.drugCategoryChildName});
						if(resII.code===200){ this.drugCategoryChildOption=resII.data }
					break;
					case 10: //药理类别3
						let resIII = await selectThreeCateGory({idcode:this.idcode,threeLevelDrugCategoryName:this.addForm.threeLevelDrugCategoryName});
						if(resIII.code===200){ this.threeLevelDrugCategoryOption=resIII.data }
					break;
					case 11: //毒麻类型
						let dm = await selectDocVtByType();
						if(dm.code===200){ this.poisonousTypeOption=dm.data }
					break;
					case 19: //病案费别
						console.log('病案费别')
						let fb = await getRecordCategory();
						if(fb.code===200){ this.medicalRecordFeeOption=fb.data }
					break;
				}
			},
			// selectChance
			handleChange(v,i){
				switch (i) {
					case 8:
					let idcode1 = this.addForm.drugCategory
					this.idcode = this.drugCategoryOption.filter(item => item.id === idcode1)[0].idcode;
					this.addForm.drugCategoryName = this.drugCategoryOption.filter(item => item.id === idcode1)[0].label;
					this.addForm.drugCategory ? this.disabledCategory = false : this.disabledCategory = true;
					break;
					case 9:
					let idcode2 = this.addForm.drugCategoryChild
					this.idcode = this.drugCategoryChildOption.filter(item => item.id === idcode2)[0].idcode;
					this.addForm.drugCategoryChildName = this.drugCategoryChildOption.filter(item => item.id === idcode2)[0].label;
					break;
					case 10:
					let idcode3 = this.addForm.threeLevelDrugCategory
					this.idcode = this.threeLevelDrugCategoryOption.filter(item => item.id === idcode3)[0].idcode;
					this.addForm.threeLevelDrugCategoryName = this.threeLevelDrugCategoryOption.filter(item => item.id === idcode3)[0].label;
					break;
					case 14:
					this.addForm.isAntibiotic == 1 ? this.disabledKss = false : this.disabledKss = true;
					this.addForm.antibioticLevel == ''
					break;
				}
			},
			// selectChance

			// input失焦 简码转换赋值
			inputChance(v,i){
				// i event
				switch (i) {
					case 3:  // 通用名失焦开始赋值
					this.editForm.simplifiedCode = this.makePy(this.editForm.genericName).toUpperCase()
					break;
				}
			},
			
			// 关闭Model
			handleEditClose(done){
				this.reload();
				done();
			},
			
		},

	}
</script>

<style lang="less" scoped>
.content{
	height: 100%;
	width: 100%;
	.header{
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #007bb0;
		padding: 4px;
	}
	.main{
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		
	}
}
</style>